const express = require("express");

const app = express();

const cookieparse = require("cookie-parser");

app.listen(4000,()=>{
    console.log("4000端口已经打开");
})
app.use(cookieparse());
app.get("/setcookie",(req,res)=>{
    res.cookie("USER","刘冬");
    res.cookie("AGE",21,{maxAge:10*1000});//res.cookie(名称,值，maxAge有效时间);
    res.send(`<script>alert("cookie设置成功");location.href='/getcookie'</script>`)
})
app.get("/getcookie",(req,res)=>{
    let {USER="",AGE=""} = req.cookies;
    res.send(`欢迎${USER} ${AGE}访问此网站`);
})
